<template>
  <div class="header">
    <div class="page-title">车辆管理</div>
    <el-form :inline="true" :model="form" class="demo-form-inline">
      <el-form-item label="车牌号">
        <el-input v-model="form.license_plate" placeholder="车牌号"></el-input>
      </el-form-item>
      <el-form-item label="门店">
        <el-select v-model="form.store_id" placeholder="门店">
          <el-option label="请选择" value="0"></el-option>
          <el-option
              v-for="item in listData"
              :key="item.id"
              :label="item.name"
              :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商户" v-if="isAdmin=='admin'">
        <el-select v-model="form.manager_id" placeholder="商户">
          <el-option label="请选择" value="0"></el-option>
          <el-option
              v-for="manager in managerData"
              :key="manager.id"
              :label="manager.username"
              :value="manager.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" class="m-t-5" :key="num">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="id" label="id" width="100"></el-table-column>
      <el-table-column prop="manager" label="商户名称"></el-table-column>
      <el-table-column prop="store_name" label="门店名称"></el-table-column>
      <el-table-column
        prop="user.wxname"
        label="微信名"
        width="150"
      ></el-table-column>
      <el-table-column label="头像" width="200" class="t-c">
        <template #default="v">
          <el-image :src="v.row.user.wximage" fit="cover"></el-image>
        </template>
      </el-table-column>

      <el-table-column
        prop="license_plate"
        label="车牌号"
        width="150"
      ></el-table-column>

      <el-table-column
        prop="name"
        label="姓名"
        width="200"
      ></el-table-column>

      <el-table-column
        prop="phone"
        label="手机号"
        width="200"
      ></el-table-column>

      <el-table-column
        prop="license_type"
        label="车牌类型"
        width="200"
      ></el-table-column>


    </el-table>
    
    <el-pagination
      background
      hide-on-single-page
      layout="prev, pager, next"
      :total="total"
      :current-page="current"
      @current-change="changePage"
    >
    </el-pagination>
  </div>
</template>
<script>

import { request_cars,request_store_lists,request_get_managers } from "@/util/api";

export default {
  name: "SeekType",
  data() {
    return {
      current: 1,
      total: 0,
      isAdmin:JSON.parse(sessionStorage.getItem('userinfo')).username,
      listData:{},
      managerData:{},
      form: {
        license_plate:'',
        store_id:'',
        manager_id:'',
        page:1,
      },
      num:1,
      searchContent: '',
      dialogFormVisible: false,
    };
  },
  computed: {},
  mounted() {
    this.init();
  },
  methods: {
    init() {
        this.changePage(1)
        this.getStoreLists()
        this.getManagerLists()
    },
    //查询门店列表
    getStoreLists(){
      request_store_lists().then((res)=>{
        const result = res.data;
        if (result.code == 200) {
          this.listData = result.data;
        }
      }).catch()
    },
    //查询商户列表
    getManagerLists(){
      request_get_managers().then((res)=>{
        const result = res.data;
        if (result.code == 200) {
          this.managerData = result.data;
        }
      }).catch()
    },
    /**
     * 查询列表
     */
    onSubmit() {
      request_cars(this.form).then((res)=>{
        const result = res.data;
        if (result.code == 200) {
          this.tableData = result.data.data;
          this.total = result.data.total;
          this.current = result.data.current;
          this.num = 13;
        }
      }).catch()
      console.log('submit!');
    },
    // 搜索
    search() {
      this.changePage(1);
    },
    // 分页
    changePage(page) {
      request_cars({
        page,
      })
        .then((res) => {
          const result = res.data;
          if (result.code == 200) {
            this.tableData = result.data.data;
            this.total = result.data.total;
            this.current = result.data.current;
            this.num = 13;
          }
        })
        .catch();
    },
  },
};
</script>

<style scoped  lang="less">
</style>